package model.feature;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import model.Settings;
import util.PlayerUtilities;

public class FeatureItems {

	private int Id;
	private String date;
	private String type;
	private String image;
	private String textTop;
	private String textBottom;
	private String textMiddle;
	
	private static FeatureItems _instance;

	private FeatureItems()
	{

	}

	public static FeatureItems getInstance()
	{
		if(_instance == null)
		{
			_instance = new FeatureItems();
		}
		return _instance;
	}

	@SuppressWarnings("unchecked")
	public Map<Integer, FeatureItems> getFeatureItemsList()
	{
		Map<Integer, FeatureItems> featureRecords = new HashMap<Integer, FeatureItems>();

		System.out.println(Settings.FEATURE_XML);
		if(!new File(Settings.FEATURE_XML).exists()){
			System.out.println("Doesn't exist");
			return featureRecords;
		}

		if (new File(Settings.FEATURE_XML).exists()) {
			Object obj = PlayerUtilities.getObjectFromXMLFile(Settings.FEATURE_XML);
			if (obj != null) {
				featureRecords = (Map<Integer, FeatureItems>) obj;
			} else {
				System.out.println("Failed to read " + Settings.FEATURE_XML);
			}
		}

		return featureRecords;
	}
	
	public void saveToXML() {
		System.out.println("saving feature to xml.");
		Map<Integer,FeatureItems> obj = getFeatureItemsList();
		//PlayerUtilities.saveObjectToXMLFile(Settings.RESOURCES_DIRECTORY+"/himadri.xml", obj);
	}

	public int getId() {
		return Id;
	}

	public void setId(int id) {
		Id = id;
	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getImage() {
		return image;
	}

	public void setImage(String image) {
		this.image = image;
	}

	public String getTextTop() {
		return textTop;
	}

	public void setTextTop(String textTop) {
		this.textTop = textTop;
	}

	public String getTextBottom() {
		return textBottom;
	}

	public void setTextBottom(String textBottom) {
		this.textBottom = textBottom;
	}

	public String getTextMiddle() {
		return textMiddle;
	}

	public void setTextMiddle(String textMiddle) {
		this.textMiddle = textMiddle;
	}
	
	@Override
	public String toString() {
		return "FeatureItems [Id=" + Id + ", date=" + date + ", image=" + image
				+ ", textBottom=" + textBottom + ", textMiddle=" + textMiddle
				+ ", textTop=" + textTop + ", type=" + type + "]";
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FeatureItems.getInstance().saveToXML();
	}

}
